<template>
  <div class="user_item" @click="openMsg">
    <div class="headpic">
      <Badge :count="msgnum" :overflow-count="99">
      <img :src="user.headimgurl" alt="">
      </Badge>
    </div>
    <div class="text">
      <p class="name">
        {{user.nickname}}
        <span v-if="user.name">({{user.name}})</span>
      </p>
      
      <p class="msg" v-if="user.chatlog[user.chatlog.length - 1].type == 'text'">
        {{user.chatlog[user.chatlog.length - 1].content}}
      </p>
      <p class="msg" v-else>
        【新消息】
      </p>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'test',
    props: {
      user: {
        type: Object,
        default: {}
      },
      keys: {
        type: Number,
        default: 0
      },
      msgnum: {
        type: Number,
        default: 0
      },
      onclicks: {
        type: Function
      }
    },
    methods: {
      open (link) {
        this.$electron.shell.openExternal(link)
      },
      openMsg () {
        this.user.newmsg_num = 0
        this.onclicks(this.user, this.keys)
      }
    }
  }
</script>

<style lang="less" scoped>
  @import "./style.less";
</style>
